

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="@[toc] 历史记录 Web项目实战 | 购物系统v2.0 | 开发记录（一）需求分析 | 技术选型 | 系统设计 | 数据表设计 | SpringBoot、SSM、Thymeleaf、Bootstrap…  Web项目实战 | 购物系统v2.0 | 开发记录（二）搭建SpringBoot+SSM框架环境 | 配置Druid+MyBatis | 基于Bootstrap实现登陆页面| 图片验证码接">
<meta property="og:type" content="article">
<meta property="og:title" content="Web项目实战 _ 购物系统v2.0 _ 开发记录（四）单个页面单个请求解决根据商品类型进行分页查询 _ 使用省市区三级联动 _ 使用JQuery 插件实现图片上传">
<meta property="og:url" content="http://example.com/2022/02/05/Web%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20_%20%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2.0%20_%20%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95%EF%BC%88%E5%9B%9B%EF%BC%89%E5%8D%95%E4%B8%AA%E9%A1%B5%E9%9D%A2%E5%8D%95%E4%B8%AA%E8%AF%B7%E6%B1%82%E8%A7%A3%E5%86%B3%E6%A0%B9%E6%8D%AE%E5%95%86%E5%93%81%E7%B1%BB%E5%9E%8B%E8%BF%9B%E8%A1%8C%E5%88%86%E9%A1%B5%E6%9F%A5%E8%AF%A2%20_%20%E4%BD%BF%E7%94%A8%E7%9C%81%E5%B8%82%E5%8C%BA%E4%B8%89%E7%BA%A7%E8%81%94%E5%8A%A8%20_%20%E4%BD%BF%E7%94%A8JQuery%20%E6%8F%92%E4%BB%B6%E5%AE%9E%E7%8E%B0%E5%9B%BE%E7%89%87%E4%B8%8A%E4%BC%A0/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="@[toc] 历史记录 Web项目实战 | 购物系统v2.0 | 开发记录（一）需求分析 | 技术选型 | 系统设计 | 数据表设计 | SpringBoot、SSM、Thymeleaf、Bootstrap…  Web项目实战 | 购物系统v2.0 | 开发记录（二）搭建SpringBoot+SSM框架环境 | 配置Druid+MyBatis | 基于Bootstrap实现登陆页面| 图片验证码接">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/f07517828ed3492196d6874243ddb09a.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/42f3c70517854db9acc0d56ac2a5a032.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/1f0f7624a10f490a9abcd344979a832b.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/b64ba02ff92d4784b2fb5a1d3b6fb9ba.png">
<meta property="article:published_time" content="2022-02-05T01:18:18.000Z">
<meta property="article:modified_time" content="2022-08-22T15:50:58.129Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="JavaWeb">
<meta property="article:tag" content="项目实战:购物系统v2.0">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/f07517828ed3492196d6874243ddb09a.png">
  
  
  
  <title>Web项目实战 _ 购物系统v2.0 _ 开发记录（四）单个页面单个请求解决根据商品类型进行分页查询 _ 使用省市区三级联动 _ 使用JQuery 插件实现图片上传 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Web项目实战 _ 购物系统v2.0 _ 开发记录（四）单个页面单个请求解决根据商品类型进行分页查询 _ 使用省市区三级联动 _ 使用JQuery 插件实现图片上传"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-02-05 09:18" pubdate>
          2022年2月5日 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          21k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          172 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Web项目实战 _ 购物系统v2.0 _ 开发记录（四）单个页面单个请求解决根据商品类型进行分页查询 _ 使用省市区三级联动 _ 使用JQuery 插件实现图片上传</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p>@[toc]</p>
<h1 id="历史记录"><a href="#历史记录" class="headerlink" title="历史记录"></a>历史记录</h1><ul>
<li><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122722369">Web项目实战 | 购物系统v2.0 | 开发记录（一）需求分析 | 技术选型 | 系统设计 | 数据表设计 | SpringBoot、SSM、Thymeleaf、Bootstrap…</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122726356">Web项目实战 | 购物系统v2.0 | 开发记录（二）搭建SpringBoot+SSM框架环境 | 配置Druid+MyBatis | 基于Bootstrap实现登陆页面| 图片验证码接口</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122743352">Web项目实战 | 购物系统v2.0 | 开发记录（三）分页显示 | 根据商品名称进行模糊查询</a></p>
</li>
</ul>
<h1 id="一、运行环境"><a href="#一、运行环境" class="headerlink" title="一、运行环境"></a>一、运行环境</h1><hr>
<ul>
<li>windows10</li>
<li>IDEA 2021.1 专业版</li>
<li>JDK8</li>
<li>SpringBoot2</li>
<li>Druid 1.2.5</li>
<li>Bootstrap 4.6.0</li>
<li>MySQL 8</li>
<li>Navicat 11</li>
</ul>
<h1 id="二、根据商品类查询"><a href="#二、根据商品类查询" class="headerlink" title="二、根据商品类查询"></a>二、根据商品类查询</h1><hr>
<p>在实现此功能时有几个难点，如：1）搜索的同时要支持分页显示，保证下一页仍是当前类型；2）支持显示当前选择的类型。</p>
<p>解决思路：</p>
<p>对所有到商品页面的请求添加一个键值对，键为 <strong>comType</strong>，值为商品类型的ID，若是所有商品就设置为-1，这样在前端页面就可以用<code>th:style</code>标签直接使用三目运算符进行判断，因显示分类标签时是通过<code>th:each</code>循环显示的，所以可以得知当前的商品类型的ID。</p>
<p>除了分类按钮的显示外，还有分页的功能，之前分页请求的地址和固定类型后的请求地址不同，所以需要使用<code>th:href</code>标签借助三目运算符进行判断，若当前comType是-1，则跟原先的请求地址一样<code>/index/页数</code>，若是其他的值，那么请求的地址需要变化<code>/index/type/页数</code>。</p>
<p>至此，解决了分类显示、分页的问题，最后还有搜索商品的问题：之前的搜索是默认为所有商品的，现在需要加上一个类型的选择，这样用户可以搜索固定的类别，在前端样式上需稍作修改。</p>
<p><img src="https://img-blog.csdnimg.cn/f07517828ed3492196d6874243ddb09a.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>前端代码-搜索部分：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;nav input-group input-group-sm mt-3 container&quot;</span> <span class="hljs-attr">th:fragment</span>=<span class="hljs-string">&quot;search&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;input-group-prepend&quot;</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;btn-ctype&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn btn-outline-dark dropdown-toggle&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;button&quot;</span> <span class="hljs-attr">data-toggle</span>=<span class="hljs-string">&quot;dropdown&quot;</span> <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">&quot;false&quot;</span></span><br><span class="hljs-tag">            <span class="hljs-attr">th:text</span>=<span class="hljs-string">&quot;$&#123;comType.comTypeName&#125;&quot;</span> <span class="hljs-attr">th:data-id</span>=<span class="hljs-string">&quot;$&#123;comType.id&#125;&quot;</span>&gt;</span><br>            所有商品<br>        <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;dropdown-menu&quot;</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;dropdown-item&quot;</span>&gt;</span>所有商品<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;dropdown-item&quot;</span></span><br><span class="hljs-tag">               <span class="hljs-attr">th:each</span>=<span class="hljs-string">&quot;ct: $&#123;session.ctypeInfo&#125;&quot;</span></span><br><span class="hljs-tag">               <span class="hljs-attr">th:text</span>=<span class="hljs-string">&quot;$&#123;ct.comTypeName&#125;&quot;</span></span><br><span class="hljs-tag">               <span class="hljs-attr">th:onclick</span>=<span class="hljs-string">&quot;chose([[$&#123;ct.id&#125;]], [[$&#123;ct.comTypeName&#125;]])&quot;</span></span><br><span class="hljs-tag">               <span class="hljs-attr">th:data-id</span>=<span class="hljs-string">&quot;$&#123;ct.id&#125;&quot;</span></span><br><span class="hljs-tag">            /&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;input-search&quot;</span> <span class="hljs-attr">th:value</span>=<span class="hljs-string">&quot;$&#123;searchText&#125;&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;form-control&quot;</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">&quot;请输入查询的商品，商品名称/种类/...&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;input-group-append&quot;</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;input-group-text btn btn-info&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;btn-search&quot;</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;bi bi-search&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>前端代码-商品分页部分</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-comment">&lt;!-- 分页部分 --&gt;</span><br> <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">th:text</span>=<span class="hljs-string">&quot;&#x27;第&#x27; + $&#123;pageInfo.pageNum&#125; + &#x27;页 共&#x27; + $&#123;pageInfo.pages&#125; + &#x27;页&#x27;&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;u-text-sm text-center&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span><br> <span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">&quot;Page navigation&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;u-text-sm&quot;</span> <span class="hljs-attr">th:if</span>=<span class="hljs-string">&quot;$&#123;comInfo.size &gt; 0&#125;&quot;</span>&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;pagination justify-content-center&quot;</span>&gt;</span><br>         <span class="hljs-comment">&lt;!--首页--&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;page-item&quot;</span>&gt;</span><br>                 <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;page-link u-a-com&quot;</span></span><br><span class="hljs-tag">                    <span class="hljs-attr">th:data-type</span>=<span class="hljs-string">&quot;$&#123;comType.id&#125;&quot;</span></span><br><span class="hljs-tag">                    <span class="hljs-attr">th:data-searchtext</span>=<span class="hljs-string">&quot;$&#123;searchText&#125;&quot;</span></span><br><span class="hljs-tag">                    <span class="hljs-attr">th:data-pagenow</span>=<span class="hljs-string">&quot;$&#123;pageInfo.navigateFirstPage&#125;&quot;</span>&gt;</span><br>                     首页<br>                 <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br>         <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br>         <span class="hljs-comment">&lt;!--上一页--&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;page-item&quot;</span>&gt;</span><br>             <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;page-link u-a-com&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">th:data-type</span>=<span class="hljs-string">&quot;$&#123;comType.id&#125;&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">th:data-searchtext</span>=<span class="hljs-string">&quot;$&#123;searchText&#125;&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">th:data-pagenow</span>=<span class="hljs-string">&quot;$&#123;pageInfo.prePage&#125;&quot;</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">&quot;Previous&quot;</span>&gt;</span><br>                 <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">&quot;true&quot;</span>&gt;</span><span class="hljs-symbol">&amp;laquo;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><br>             <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br>         <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br>         <span class="hljs-comment">&lt;!--某一页--&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;page-item&quot;</span> <span class="hljs-attr">th:each</span>=<span class="hljs-string">&quot;pageNow : $&#123;pageInfo.navigatepageNums&#125;&quot;</span>&gt;</span><br>             <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">th:data-type</span>=<span class="hljs-string">&quot;$&#123;comType.id&#125;&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">th:data-searchtext</span>=<span class="hljs-string">&quot;$&#123;searchText&#125;&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">th:data-pagenow</span>=<span class="hljs-string">&quot;$&#123;pageNow&#125;&quot;</span> <span class="hljs-attr">th:text</span>=<span class="hljs-string">&quot;$&#123;pageNow&#125;&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">th:class</span>=<span class="hljs-string">&quot;&#x27;page-link u-a-com&#x27; + $&#123;pageNow == pageInfo.pageNum ? &#x27; bg-info text-light&#x27; : &#x27;&#x27;&#125;&quot;</span>&gt;</span><br>             <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br>         <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br>         <span class="hljs-comment">&lt;!--下一页--&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;page-item&quot;</span>&gt;</span><br>             <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;page-link u-a-com&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">th:data-type</span>=<span class="hljs-string">&quot;$&#123;comType.id&#125;&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">th:data-searchtext</span>=<span class="hljs-string">&quot;$&#123;searchText&#125;&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">th:data-pagenow</span>=<span class="hljs-string">&quot;$&#123;pageInfo.nextPage&#125;&quot;</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">&quot;Next&quot;</span>&gt;</span><br>             <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">&quot;true&quot;</span>&gt;</span><span class="hljs-symbol">&amp;raquo;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><br>             <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br>         <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br>         <span class="hljs-comment">&lt;!--最后一页--&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;page-item&quot;</span>&gt;</span><br>             <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;page-link u-a-com&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">th:data-type</span>=<span class="hljs-string">&quot;$&#123;comType.id&#125;&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">th:data-searchtext</span>=<span class="hljs-string">&quot;$&#123;searchText&#125;&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">th:data-pagenow</span>=<span class="hljs-string">&quot;$&#123;pageInfo.navigateLastPage&#125;&quot;</span>&gt;</span><br>                 末页<br>             <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br>         <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br>     <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span><br> <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>分页部分JS代码：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs javascript">$(<span class="hljs-string">&#x27;.u-a-com&#x27;</span>).<span class="hljs-title function_">click</span>(<span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)&#123;<br>    <span class="hljs-keyword">let</span> type = $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">data</span>(<span class="hljs-string">&#x27;type&#x27;</span>)<br>    <span class="hljs-keyword">let</span> searchText = $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">data</span>(<span class="hljs-string">&#x27;searchtext&#x27;</span>)<br>    <span class="hljs-keyword">let</span> pageNow = $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">data</span>(<span class="hljs-string">&#x27;pagenow&#x27;</span>)<br>    <span class="hljs-keyword">if</span>(searchText != <span class="hljs-literal">null</span>)<br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">attr</span>(<span class="hljs-string">&#x27;href&#x27;</span>, <span class="hljs-string">&#x27;/index.html?type=&#x27;</span> + type + <span class="hljs-string">&#x27;&amp;searchText=&#x27;</span> + searchText + <span class="hljs-string">&#x27;&amp;pageNow=&#x27;</span> + pageNow)<br>    <span class="hljs-keyword">else</span><br>        $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">attr</span>(<span class="hljs-string">&#x27;href&#x27;</span>, <span class="hljs-string">&#x27;/index.html?type=&#x27;</span> + type + <span class="hljs-string">&#x27;&amp;pageNow=&#x27;</span> + pageNow)<br>&#125;)<br></code></pre></td></tr></table></figure>
<p>控制层代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.controller;<br><br><span class="hljs-keyword">import</span> com.github.pagehelper.PageHelper;<br><span class="hljs-keyword">import</span> com.github.pagehelper.PageInfo;<br><span class="hljs-keyword">import</span> com.uni.dao.CommodityMapper;<br><span class="hljs-keyword">import</span> com.uni.dao.CommodityTypeMapper;<br><span class="hljs-keyword">import</span> com.uni.pojo.Commodity;<br><span class="hljs-keyword">import</span> com.uni.pojo.CommodityExample;<br><span class="hljs-keyword">import</span> com.uni.pojo.CommodityType;<br><span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;<br><span class="hljs-keyword">import</span> org.springframework.stereotype.Controller;<br><span class="hljs-keyword">import</span> org.springframework.ui.ModelMap;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.GetMapping;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RequestParam;<br><br><span class="hljs-keyword">import</span> java.util.List;<br><br><span class="hljs-meta">@Controller</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">CommodityAction</span> &#123;<br>    <span class="hljs-meta">@Autowired</span><br>    CommodityMapper commodityMapper;<br>    <span class="hljs-meta">@Autowired</span><br>    CommodityTypeMapper commodityTypeMapper;<br>    <span class="hljs-meta">@GetMapping(&quot;/index.html&quot;)</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">findAllByPage</span><span class="hljs-params">(ModelMap modelMap,</span><br><span class="hljs-params">                                <span class="hljs-meta">@RequestParam(value=&quot;type&quot;, defaultValue = &quot;0&quot;)</span> Integer type,</span><br><span class="hljs-params">                                <span class="hljs-meta">@RequestParam(value=&quot;searchText&quot;, defaultValue = &quot;&quot;)</span> String searchText,</span><br><span class="hljs-params">                                <span class="hljs-meta">@RequestParam(value = &quot;pageNow&quot; , defaultValue = &quot;1&quot;)</span> Integer pageNow,</span><br><span class="hljs-params">                                <span class="hljs-meta">@RequestParam(value = &quot;pageSize&quot;, defaultValue = &quot;10&quot;)</span> Integer pageSize)</span>&#123;<br>        PageHelper.startPage(pageNow, pageSize);<br>        <span class="hljs-type">CommodityExample</span> <span class="hljs-variable">example</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">CommodityExample</span>();<br>        CommodityExample.<span class="hljs-type">Criteria</span> <span class="hljs-variable">criteria</span> <span class="hljs-operator">=</span> example.createCriteria();<br>        <span class="hljs-keyword">if</span>(type != <span class="hljs-number">0</span>)<br>            criteria.andComTypeEqualTo(type);<br>        criteria.andComNameLike(<span class="hljs-string">&quot;%&quot;</span> + searchText + <span class="hljs-string">&quot;%&quot;</span>);<br>        List&lt;Commodity&gt; comInfo = commodityMapper.selectByExample(example);<br>        PageInfo&lt;Commodity&gt; pageInfo = <span class="hljs-keyword">new</span> <span class="hljs-title class_">PageInfo</span>&lt;&gt;(comInfo);<br>        <span class="hljs-comment">// 首页设置上一个页面为1，防止上一页到末页</span><br>        <span class="hljs-keyword">if</span>(pageNow == <span class="hljs-number">1</span>) pageInfo.setPrePage(<span class="hljs-number">1</span>);<br>        <span class="hljs-comment">// 末页设置最后一个页面，防止下一页到首页</span><br>        <span class="hljs-keyword">if</span>(pageInfo.getNextPage() == <span class="hljs-number">0</span>) pageInfo.setNextPage(Math.min(pageInfo.getPrePage() + <span class="hljs-number">1</span>, pageInfo.getPageNum()));<br>        <span class="hljs-comment">// 查询商品类型</span><br>        comInfo.forEach(com -&gt; &#123;<br>            com.setCommodityType(commodityTypeMapper.selectByPrimaryKey(com.getComType()));<br>        &#125;);<br>        modelMap.addAttribute(<span class="hljs-string">&quot;pageNow&quot;</span>, pageNow);<br>        modelMap.addAttribute(<span class="hljs-string">&quot;pageSize&quot;</span>, pageSize);<br>        modelMap.addAttribute(<span class="hljs-string">&quot;comInfo&quot;</span>, comInfo);<br>        modelMap.addAttribute(<span class="hljs-string">&quot;pageInfo&quot;</span>, pageInfo);<br>        modelMap.addAttribute(<span class="hljs-string">&quot;searchText&quot;</span>, searchText);<br>        modelMap.addAttribute(<span class="hljs-string">&quot;comType&quot;</span>, type == <span class="hljs-number">0</span> ?<br>                <span class="hljs-keyword">new</span> <span class="hljs-title class_">CommodityType</span>(<span class="hljs-number">0</span>, <span class="hljs-string">&quot;所有商品&quot;</span>): commodityTypeMapper.selectByPrimaryKey(type));<br>        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;index&quot;</span>;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h1 id="三、使用JQuery插件实现图片上传"><a href="#三、使用JQuery插件实现图片上传" class="headerlink" title="三、使用JQuery插件实现图片上传"></a>三、使用JQuery插件实现图片上传</h1><hr>
<p>插件地址：<a target="_blank" rel="noopener" href="https://www.jq22.com/jquery-info18167">点击访问</a></p>
<p>下载好插件后将JS、CSS插件复制到项目里，然后参考给出的index.html样例对自己的项目进行修改，最后的效果：</p>
<p><img src="https://img-blog.csdnimg.cn/42f3c70517854db9acc0d56ac2a5a032.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h1 id="四、JS实现省市区三级联动"><a href="#四、JS实现省市区三级联动" class="headerlink" title="四、JS实现省市区三级联动"></a>四、JS实现省市区三级联动</h1><hr>
<h2 id="4-1-基本实现"><a href="#4-1-基本实现" class="headerlink" title="4.1 基本实现"></a>4.1 基本实现</h2><p>全国省市地区信息的 MySql 数据代码 ：<a target="_blank" rel="noopener" href="https://gitee.com/ccuni/code-base/blob/master/mysql/web/%E5%85%A8%E5%9B%BD%E7%9C%81%E5%B8%82%E5%8C%BA%E4%BF%A1%E6%81%AF%E8%A1%A8.sql#">点击查看</a></p>
<p>SQL脚本执行后的结果：<br><img src="https://img-blog.csdnimg.cn/1f0f7624a10f490a9abcd344979a832b.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>为了方便JDBC操作，笔者依旧采用之前MyBatis逆向工程的方式<a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122726356">【点击查看】</a>，不用手写Mapper接口和映射文件。MyBatis逆向工程的配置</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span>?&gt;</span><br><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-keyword">generatorConfiguration</span></span><br><span class="hljs-meta">        <span class="hljs-keyword">PUBLIC</span> <span class="hljs-string">&quot;-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN&quot;</span></span><br><span class="hljs-meta">        <span class="hljs-string">&quot;http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd&quot;</span>&gt;</span><br><br><span class="hljs-tag">&lt;<span class="hljs-name">generatorConfiguration</span>&gt;</span><br><br>    <span class="hljs-comment">&lt;!-- context 运行上下文 --&gt;</span><br>    <span class="hljs-comment">&lt;!-- id 必唯一 --&gt;</span><br>    <span class="hljs-comment">&lt;!-- defaultModelType:可选;flat:所有内容（主键，blob）等全部生成在一个对象中 --&gt;</span><br>    <span class="hljs-comment">&lt;!-- targetRuntime:可选 ;建议:MyBatis3Simple/MyBatis3 --&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">context</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;MySqlTables&quot;</span> <span class="hljs-attr">defaultModelType</span>=<span class="hljs-string">&quot;flat&quot;</span></span><br><span class="hljs-tag">             <span class="hljs-attr">targetRuntime</span>=<span class="hljs-string">&quot;MyBatis3&quot;</span>&gt;</span><br><br>        <span class="hljs-comment">&lt;!--beginningDelimiter和endingDelimiter：指明数据库的用于标记数据库对象名的符号 --&gt;</span><br>        <span class="hljs-comment">&lt;!--如ORACLE就是双引号；MYSQL默认是`反引号； --&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;beginningDelimiter&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;`&quot;</span> /&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;endingDelimiter&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;`&quot;</span> /&gt;</span><br><br>        <span class="hljs-comment">&lt;!-- 指定生成的java文件的编码,没有直接生成到项目时中文可能会乱码 --&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;javaFileEncoding&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;UTF-8&quot;</span> /&gt;</span><br><br>        <span class="hljs-comment">&lt;!-- 格式化java代码 --&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;javaFormatter&quot;</span></span><br><span class="hljs-tag">                  <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;org.mybatis.generator.api.dom.DefaultJavaFormatter&quot;</span> /&gt;</span><br><br>        <span class="hljs-comment">&lt;!-- 格式化XML代码 --&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;xmlFormatter&quot;</span></span><br><span class="hljs-tag">                  <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;org.mybatis.generator.api.dom.DefaultXmlFormatter&quot;</span> /&gt;</span><br><br>        <span class="hljs-comment">&lt;!--自动实现Serializable可序列化接口 --&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;org.mybatis.generator.plugins.SerializablePlugin&quot;</span> /&gt;</span><br><br>        <span class="hljs-comment">&lt;!--去除生成的注释;建议初次不去注释 --&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">commentGenerator</span>&gt;</span><br>            <span class="hljs-comment">&lt;!-- 去除自动生成时的时间戳 --&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;suppressDate&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span> /&gt;</span><br>            <span class="hljs-comment">&lt;!-- 去除自动生成的注释 --&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;suppressAllComments&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span> /&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">commentGenerator</span>&gt;</span><br><br>        <span class="hljs-comment">&lt;!--数据库基本信息 --&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">jdbcConnection</span> <span class="hljs-attr">driverClass</span>=<span class="hljs-string">&quot;com.mysql.cj.jdbc.Driver&quot;</span></span><br><span class="hljs-tag">                        <span class="hljs-attr">connectionURL</span>=<span class="hljs-string">&quot;jdbc:mysql://localhost:3306/simple_shop_system_2?characterEncoding=UTF-8&quot;</span></span><br><span class="hljs-tag">                        <span class="hljs-attr">userId</span>=<span class="hljs-string">&quot;root&quot;</span></span><br><span class="hljs-tag">                        <span class="hljs-attr">password</span>=<span class="hljs-string">&quot;数据库密码&quot;</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">jdbcConnection</span>&gt;</span><br><br>        <span class="hljs-comment">&lt;!-- java类型处理器 用于处理DB中的类型到Java中的类型，默认使用JavaTypeResolverDefaultImpl； --&gt;</span><br>        <span class="hljs-comment">&lt;!-- 注意一点，默认会先尝试使用Integer，Long，Short等来对应DECIMAL和 NUMERIC数据类型； --&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">javaTypeResolver</span></span><br><span class="hljs-tag">                <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl&quot;</span>&gt;</span><br>            <span class="hljs-comment">&lt;!-- true：使用BigDecimal对应DECIMAL和 NUMERIC数据类型 --&gt;</span><br>            <span class="hljs-comment">&lt;!--false：默认, --&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;forceBigDecimals&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;false&quot;</span> /&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">javaTypeResolver</span>&gt;</span><br><br>        <span class="hljs-comment">&lt;!--Java model(POJO)生成的位置 --&gt;</span><br>        <span class="hljs-comment">&lt;!--targetPackage:包路径 --&gt;</span><br>        <span class="hljs-comment">&lt;!--targetProject:项目路径 --&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">javaModelGenerator</span> <span class="hljs-attr">targetPackage</span>=<span class="hljs-string">&quot;com.uni.pojo&quot;</span></span><br><span class="hljs-tag">                            <span class="hljs-attr">targetProject</span>=<span class="hljs-string">&quot;src/main/java&quot;</span>&gt;</span><br>            <span class="hljs-comment">&lt;!-- enableSubPackages:是否让schema作为包的后缀 --&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;enableSubPackages&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span> /&gt;</span><br>            <span class="hljs-comment">&lt;!-- 从数据库返回的值被清理前后的空格 --&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;trimStrings&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span> /&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">javaModelGenerator</span>&gt;</span><br><br>        <span class="hljs-comment">&lt;!--*Mapper.xml生成的位置 --&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">sqlMapGenerator</span> <span class="hljs-attr">targetPackage</span>=<span class="hljs-string">&quot;mybatis.mapper&quot;</span></span><br><span class="hljs-tag">                         <span class="hljs-attr">targetProject</span>=<span class="hljs-string">&quot;src/main/resources&quot;</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;enableSubPackages&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span> /&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">sqlMapGenerator</span>&gt;</span><br><br>        <span class="hljs-comment">&lt;!-- 对于mybatis来说，即生成Mapper接口，注意，如果没有配置该元素，那么默认不会生成Mapper接口 --&gt;</span><br>        <span class="hljs-comment">&lt;!--type：选择怎么生成mapper接口（在MyBatis3/MyBatis3Simple下） --&gt;</span><br>        <span class="hljs-comment">&lt;!--1，ANNOTATEDMAPPER：会生成使用Mapper接口+Annotation的方式创建（SQL生成在annotation中），不会生成对应的XML --&gt;</span><br>        <span class="hljs-comment">&lt;!--2，MIXEDMAPPER：使用混合配置，会生成Mapper接口，并适当添加合适的Annotation，但是XML会生成在XML中 --&gt;</span><br>        <span class="hljs-comment">&lt;!--3，XMLMAPPER：会生成Mapper接口，接口完全依赖XML --&gt;</span><br>        <span class="hljs-comment">&lt;!--注意，如果context是MyBatis3Simple：只支持ANNOTATEDMAPPER和XMLMAPPER --&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">javaClientGenerator</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;XMLMAPPER&quot;</span></span><br><span class="hljs-tag">                             <span class="hljs-attr">targetPackage</span>=<span class="hljs-string">&quot;com.uni.dao&quot;</span> <span class="hljs-attr">targetProject</span>=<span class="hljs-string">&quot;src/main/java&quot;</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;enableSubPackages&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span> /&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">javaClientGenerator</span>&gt;</span><br>        <span class="hljs-comment">&lt;!--表的名称;对应类的名称; --&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">tableName</span>=<span class="hljs-string">&quot;province&quot;</span> <span class="hljs-attr">domainObjectName</span>=<span class="hljs-string">&quot;Province&quot;</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;useActualColumnNames&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span>/&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">tableName</span>=<span class="hljs-string">&quot;city&quot;</span> <span class="hljs-attr">domainObjectName</span>=<span class="hljs-string">&quot;City&quot;</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;useActualColumnNames&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span>/&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span><br>                <span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">tableName</span>=<span class="hljs-string">&quot;area&quot;</span> <span class="hljs-attr">domainObjectName</span>=<span class="hljs-string">&quot;Area&quot;</span>&gt;</span><br>                    <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;useActualColumnNames&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span>/&gt;</span><br>                <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">context</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">generatorConfiguration</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>跟之前一样，使用Maven插件生成完毕后，在DAO层的Mapper接口类上方添加<code>@Component</code>注解，注入到Spring IoC容器中，同时在相应的pojo类都添加<code>toString()</code>方法，笔者建议用lombok包，使用<code>@Data</code>注解就能实现，特别方便。</p>
<p>PS：SpringBoot项目记得设置支持扫描通过注解标记的Mapper接口类的包，方法有多种，笔者是在SpringBoot启动类上方使用<code>@MapperScan(value = &quot;DAO层所在包名&quot;)</code>的注解。</p>
<p><strong>测试代码：</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Autowired</span><br>ProvinceMapper provinceMapper;<br><span class="hljs-meta">@Autowired</span><br>CityMapper cityMapper;<br><span class="hljs-meta">@Test</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">TestProvinceCityArea</span><span class="hljs-params">()</span>&#123;<br>    <span class="hljs-comment">/* 设置省份的查询条件 */</span><br>    <span class="hljs-type">ProvinceExample</span> <span class="hljs-variable">provinceExample</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">ProvinceExample</span>()&#123;&#123;<br>        createCriteria().andNameLike(<span class="hljs-string">&quot;%浙江%&quot;</span>);<br>    &#125;&#125;;<br>    <span class="hljs-comment">/* 根据条件查询省份 -&gt; 浙江 */</span><br>    List&lt;Province&gt; provinces = provinceMapper.selectByExample(provinceExample);<br>    <span class="hljs-type">Province</span> <span class="hljs-variable">ZheJiang</span> <span class="hljs-operator">=</span> provinces.get(<span class="hljs-number">0</span>);<br><br>    <span class="hljs-comment">/* 设置的城市查询条件 */</span><br>    <span class="hljs-type">CityExample</span> <span class="hljs-variable">cityExample</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">CityExample</span>()&#123;&#123;<br>        createCriteria().andProvincecodeEqualTo(ZheJiang.getCode());<br>    &#125;&#125;;<br>    <span class="hljs-comment">// 输出浙江省的信息 </span><br>    System.out.println(ZheJiang);<br>    <span class="hljs-comment">// 根据省份ID -&gt; 浙江省ID 查找城市</span><br>    cityMapper.selectByExample(cityExample).forEach(city -&gt; System.out.println(city));<br>&#125;<br></code></pre></td></tr></table></figure>
<p><strong>运行结果：</strong><br><img src="https://img-blog.csdnimg.cn/b64ba02ff92d4784b2fb5a1d3b6fb9ba.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>控制层，负责返回数据库的数据：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.controller;<br><br><span class="hljs-keyword">import</span> com.alibaba.fastjson.JSON;<br><span class="hljs-keyword">import</span> com.uni.dao.AreaMapper;<br><span class="hljs-keyword">import</span> com.uni.dao.CityMapper;<br><span class="hljs-keyword">import</span> com.uni.dao.ProvinceMapper;<br><span class="hljs-keyword">import</span> com.uni.pojo.*;<br><span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.GetMapping;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RestController;<br><br><span class="hljs-keyword">import</span> java.util.List;<br><br><span class="hljs-meta">@RestController</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">AddressAction</span> &#123;<br>    <span class="hljs-meta">@Autowired</span><br>    ProvinceMapper provinceMapper;<br>    <span class="hljs-meta">@Autowired</span><br>    CityMapper cityMapper;<br>    <span class="hljs-meta">@Autowired</span><br>    AreaMapper areaMapper;<br><br>    <span class="hljs-meta">@GetMapping(&quot;/getProvinces&quot;)</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getProvinces</span><span class="hljs-params">()</span>&#123;<br>        <span class="hljs-keyword">return</span> JSON.toJSONString(provinceMapper.selectByExample(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ProvinceExample</span>()));<br>    &#125;<br>    <span class="hljs-meta">@GetMapping(&quot;/getCities&quot;)</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getCities</span><span class="hljs-params">(String provCode)</span>&#123;<br>        <span class="hljs-type">CityExample</span> <span class="hljs-variable">cityExample</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">CityExample</span>() &#123;&#123;<br>            createCriteria().andProvincecodeEqualTo(provCode);<br>        &#125;&#125;;<br>        List&lt;City&gt; cities = cityMapper.selectByExample(cityExample);<br>        <span class="hljs-keyword">return</span> JSON.toJSONString(cities);<br>    &#125;<br>    <span class="hljs-meta">@GetMapping(&quot;/getAreas&quot;)</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getAreas</span><span class="hljs-params">(String cityCode)</span>&#123;<br>        <span class="hljs-type">AreaExample</span> <span class="hljs-variable">areaExample</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">AreaExample</span>()&#123;&#123;<br>            createCriteria().andCitycodeEqualTo(cityCode);<br>        &#125;&#125;;<br>        List&lt;Area&gt; areas = areaMapper.selectByExample(areaExample);<br>        <span class="hljs-keyword">return</span> JSON.toJSONString(areas);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<p>实现省市区三级联动的JS代码：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-comment">/* 省市三级联动 */</span>                                                                                         <br><span class="hljs-comment">// 获取用户的信息                                                                                           </span><br><span class="hljs-keyword">var</span> userProvince = $(<span class="hljs-string">&#x27;select[name=&quot;userProvince&quot;]&#x27;</span>).<span class="hljs-title function_">data</span>(<span class="hljs-string">&#x27;addr&#x27;</span>)                                     <br><span class="hljs-keyword">var</span> userCity = $(<span class="hljs-string">&#x27;select[name=&quot;userCity&quot;]&#x27;</span>).<span class="hljs-title function_">data</span>(<span class="hljs-string">&#x27;addr&#x27;</span>)                                             <br><span class="hljs-keyword">var</span> userArea = $(<span class="hljs-string">&#x27;select[name=&quot;userArea&quot;]&#x27;</span>).<span class="hljs-title function_">data</span>(<span class="hljs-string">&#x27;addr&#x27;</span>)                                             <br><span class="hljs-keyword">var</span> userAddress = $(<span class="hljs-string">&#x27;input[name=&quot;userAddress&quot;]&#x27;</span>).<span class="hljs-title function_">data</span>(<span class="hljs-string">&#x27;addr&#x27;</span>)                                        <br>                                                                                                     <br>$(<span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) &#123;                                                                                       <br>                                                                                                     <br>    <span class="hljs-comment">// 初始化省市区                                                                                        </span><br>    <span class="hljs-title function_">initAddress</span>();                                                                                   <br>    <span class="hljs-comment">// 更改省份后的操作                                                                                      </span><br>    $(<span class="hljs-string">&quot;select[name=&#x27;userProvince&#x27;]&quot;</span>).<span class="hljs-title function_">change</span>(<span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) &#123;                                             <br>        <span class="hljs-keyword">var</span> provCode = $(<span class="hljs-string">&quot;select[name=&#x27;userProvince&#x27;]&quot;</span>).<span class="hljs-title function_">val</span>();                                       <br>        <span class="hljs-title function_">getCity</span>(provCode);                                                                           <br>    &#125;);                                                                                              <br>                                                                                                     <br>    <span class="hljs-comment">// 更改城市后的操作                                                                                      </span><br>    $(<span class="hljs-string">&quot;select[name=&#x27;userCity&#x27;]&quot;</span>).<span class="hljs-title function_">change</span>(<span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) &#123;                                                 <br>        <span class="hljs-keyword">var</span> cityCode = $(<span class="hljs-string">&quot;select[name=&#x27;userCity&#x27;]&quot;</span>).<span class="hljs-title function_">val</span>();                                           <br>        <span class="hljs-title function_">getArea</span>(cityCode);                                                                           <br>    &#125;);                                                                                              <br>                                                                                                     <br>&#125;);                                                                                                  <br>                                                                                                     <br><span class="hljs-keyword">function</span> <span class="hljs-title function_">initAddress</span>(<span class="hljs-params"></span>) &#123;                                                                             <br>    $(<span class="hljs-string">&#x27;input[name=&quot;userAddress&quot;]&#x27;</span>).<span class="hljs-title function_">val</span>(userAddress)                                                  <br>    <span class="hljs-keyword">var</span> firstProvCode =<span class="hljs-string">&#x27;0&#x27;</span>;                                                                          <br>    <span class="hljs-comment">// ajax请求所有省份                                                                                    </span><br>    $.<span class="hljs-title function_">get</span>(&#123;                                                                                          <br>        <span class="hljs-attr">url</span>: <span class="hljs-string">&quot;/getProvinces&quot;</span>,                                                                        <br>        <span class="hljs-attr">dataType</span>: <span class="hljs-string">&#x27;JSON&#x27;</span>,                                                                            <br>        <span class="hljs-attr">error</span>: <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> &#123;                                                                            <br>            <span class="hljs-title function_">alert</span>(<span class="hljs-string">&#x27;获取省份失败.&#x27;</span>)                                                                         <br>            <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(err.<span class="hljs-property">responseText</span>)                                                          <br>        &#125;,                                                                                           <br>        <span class="hljs-attr">success</span>: <span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span> &#123;                                                                         <br>            $.<span class="hljs-title function_">each</span>(data, <span class="hljs-keyword">function</span>(<span class="hljs-params">i, d</span>) &#123;                                                            <br>                <span class="hljs-keyword">if</span>(d.<span class="hljs-property">name</span> === userProvince) firstProvCode = d.<span class="hljs-property">code</span>                                   <br>                $(<span class="hljs-string">&quot;select[name=&#x27;userProvince&#x27;]&quot;</span>).<span class="hljs-title function_">append</span>(                                             <br>                    <span class="hljs-string">&quot;&lt;option value=&#x27;&quot;</span> + d.<span class="hljs-property">code</span> + (d.<span class="hljs-property">name</span>===userProvince ? <span class="hljs-string">&quot;&#x27; selected&gt;&quot;</span> : <span class="hljs-string">&quot;&#x27;&gt;&quot;</span>) + d.<span class="hljs-property">n</span><br>                    + <span class="hljs-string">&quot;&lt;/option&gt;&quot;</span>);                                                                  <br>            &#125;);                                                                                      <br>            <span class="hljs-comment">// 获取第一个省份的code                                                                          </span><br>            <span class="hljs-keyword">if</span>(firstProvCode != <span class="hljs-string">&#x27;0&#x27;</span>)                                                                 <br>                $(<span class="hljs-string">&quot;select[name=&#x27;userProvince&#x27;]&quot;</span>).<span class="hljs-title function_">css</span>(<span class="hljs-string">&#x27;value&#x27;</span>, userProvince)                          <br>            <span class="hljs-keyword">else</span>                                                                                     <br>                firstProvCode = data[<span class="hljs-number">0</span>].<span class="hljs-property">code</span>;                                                        <br>            <span class="hljs-comment">// 根据第一个省份code获取对应城市列表                                                                   </span><br>             <span class="hljs-title function_">getCity</span>(firstProvCode);                                                                 <br>        &#125;                                                                                            <br>    &#125;);                                                                                              <br>                                                                                                     <br>&#125;                                                                                                    <br>                                                                                                     <br><span class="hljs-comment">//获取对应城市列表（里面包括获取第一个城市的区县列表）                                                                         </span><br><span class="hljs-keyword">function</span> <span class="hljs-title function_">getCity</span>(<span class="hljs-params">provCode</span>) &#123;                                                                         <br>                                                                                                     <br>    <span class="hljs-keyword">var</span> firstCityCode = <span class="hljs-string">&#x27;0&#x27;</span>;                                                                         <br>                                                                                                     <br>    <span class="hljs-comment">// ajax请求所有市级单位                                                                                  </span><br>    $.<span class="hljs-title function_">get</span>(&#123;                                                                                          <br>        <span class="hljs-attr">url</span>: <span class="hljs-string">&quot;/getCities&quot;</span>,                                                                           <br>        <span class="hljs-attr">data</span>: &#123;<span class="hljs-attr">provCode</span>:provCode&#125;,                                                                   <br>        <span class="hljs-attr">dataType</span>: <span class="hljs-string">&#x27;JSON&#x27;</span>,                                                                            <br>        <span class="hljs-attr">error</span>: <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> &#123;                                                                            <br>            <span class="hljs-title function_">alert</span>(<span class="hljs-string">&#x27;获取市区失败.&#x27;</span>)                                                                         <br>            <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(err.<span class="hljs-property">responseText</span>)                                                          <br>        &#125;,                                                                                           <br>        <span class="hljs-attr">success</span>: <span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span> &#123;                                                                         <br>            <span class="hljs-comment">// 先清空城市下拉框                                                                              </span><br>            $(<span class="hljs-string">&quot;select[name=&#x27;userCity&#x27;]&quot;</span>).<span class="hljs-title function_">empty</span>();                                                    <br>                                                                                                     <br>            $.<span class="hljs-title function_">each</span>(data, <span class="hljs-keyword">function</span>(<span class="hljs-params">i, d</span>) &#123;                                                            <br>                <span class="hljs-keyword">if</span>(d.<span class="hljs-property">name</span> === userCity) firstCityCode = d.<span class="hljs-property">code</span>                                       <br>                $(<span class="hljs-string">&quot;select[name=&#x27;userCity&#x27;]&quot;</span>).<span class="hljs-title function_">append</span>(                                                 <br>                    <span class="hljs-string">&quot;&lt;option value=&#x27;&quot;</span> + d.<span class="hljs-property">code</span> + (d.<span class="hljs-property">name</span>===userCity ? <span class="hljs-string">&quot;&#x27; selected&gt;&quot;</span> : <span class="hljs-string">&quot;&#x27;&gt;&quot;</span>) + d.<span class="hljs-property">name</span> <br>                    + <span class="hljs-string">&quot;&lt;/option&gt;&quot;</span>);                                                                  <br>            &#125;);                                                                                      <br>                                                                                                     <br>            <span class="hljs-comment">// 获取第一个城市的code                                                                          </span><br>            <span class="hljs-keyword">if</span>(firstCityCode != <span class="hljs-string">&#x27;0&#x27;</span>) &#123;                                                               <br>                $(<span class="hljs-string">&quot;select[name=&#x27;userCity&#x27;]&quot;</span>).<span class="hljs-title function_">attr</span>(<span class="hljs-string">&#x27;value&#x27;</span>, userCity)                                 <br>            &#125;<span class="hljs-keyword">else</span> firstCityCode = data[<span class="hljs-number">0</span>].<span class="hljs-property">code</span>;                                                      <br>            <span class="hljs-comment">// 根据第一个城市code获取对应区县列表                                                                   </span><br>            <span class="hljs-title function_">getArea</span>(firstCityCode);                                                                  <br>        &#125;                                                                                            <br>    &#125;)                                                                                               <br>                                                                                                     <br>&#125;                                                                                                    <br>                                                                                                     <br><span class="hljs-keyword">function</span> <span class="hljs-title function_">getArea</span>(<span class="hljs-params">cityCode</span>) &#123;                                                                         <br>                                                                                                     <br>    <span class="hljs-comment">// ajax请求所有区县单位                                                                                  </span><br>    $.<span class="hljs-title function_">get</span>(&#123;                                                                                          <br>        <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;/getAreas&#x27;</span>,                                                                            <br>        <span class="hljs-attr">data</span>: &#123;<span class="hljs-attr">cityCode</span>:cityCode&#125;,                                                                   <br>        <span class="hljs-attr">dataType</span>: <span class="hljs-string">&#x27;JSON&#x27;</span>,                                                                            <br>        <span class="hljs-attr">error</span>: <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span>&#123;                                                                             <br>            <span class="hljs-title function_">alert</span>(<span class="hljs-string">&#x27;获取地区信息失败.&#x27;</span>)                                                                       <br>            <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(err.<span class="hljs-property">responseText</span>)                                                          <br>        &#125;,                                                                                           <br>        <span class="hljs-attr">success</span>: <span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span> &#123;                                                                         <br>            <span class="hljs-comment">// 先清空区县下拉框                                                                              </span><br>            $(<span class="hljs-string">&quot;select[name=&#x27;userArea&#x27;]&quot;</span>).<span class="hljs-title function_">empty</span>();                                                    <br>            $.<span class="hljs-title function_">each</span>(data, <span class="hljs-keyword">function</span> (<span class="hljs-params">i, d</span>) &#123;                                                           <br>                $(<span class="hljs-string">&quot;select[name=&#x27;userArea&#x27;]&quot;</span>).<span class="hljs-title function_">append</span>(                                                 <br>                    <span class="hljs-string">&quot;&lt;option value=&#x27;&quot;</span> + d.<span class="hljs-property">code</span> + (d.<span class="hljs-property">name</span>===userArea ? <span class="hljs-string">&quot;&#x27; selected&gt;&quot;</span> : <span class="hljs-string">&quot;&#x27;&gt;&quot;</span>) + d.<span class="hljs-property">name</span> <br>                    + <span class="hljs-string">&quot;&lt;/option&gt;&quot;</span>);                                                                                                                                                     <br>            &#125;);                                                                                      <br>        &#125;                                                                                            <br>    &#125;)                                                                                               <br>&#125;                                                                                                    <br></code></pre></td></tr></table></figure>
<p>前端HTML代码：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">label</span>&gt;</span>地址:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;userProvince&quot;</span> <span class="hljs-attr">th:data-addr</span>=<span class="hljs-string">&quot;$&#123;userProvince&#125;&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;font-size: 10px&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;userCity&quot;</span> <span class="hljs-attr">th:data-addr</span>=<span class="hljs-string">&quot;$&#123;userCity&#125;&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;font-size: 10px&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;userArea&quot;</span> <span class="hljs-attr">th:data-addr</span>=<span class="hljs-string">&quot;$&#123;userArea&#125;&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;font-size: 10px&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">label</span>&gt;</span>详细地址:<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;userAddress&quot;</span> <span class="hljs-attr">th:data-addr</span>=<span class="hljs-string">&quot;$&#123;userAddress&#125;&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">&quot;详细地址&quot;</span>&gt;</span><br><br><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h2 id="4-2-优化：修改时先显示用户的地区信息"><a href="#4-2-优化：修改时先显示用户的地区信息" class="headerlink" title="4.2 优化：修改时先显示用户的地区信息"></a>4.2 优化：修改时先显示用户的地区信息</h2><p>在之前SQL表的基础上，User用户信息表里address字段表示当前用户的地址，而真正的地址有四个部分，分别为省、市&#x2F;区 、县&#x2F;镇、详细地址。</p>
<p>这里笔者采用四合一方式，使用分隔符 <code>-</code> 将四个信息连接起来成一个字符串序列</p>
<p>控制层代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.controller;<br><br><span class="hljs-keyword">import</span> com.uni.pojo.User;<br><span class="hljs-keyword">import</span> lombok.extern.log4j.Log4j2;<br><span class="hljs-keyword">import</span> org.springframework.stereotype.Controller;<br><span class="hljs-keyword">import</span> org.springframework.ui.ModelMap;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.*;<br><br><span class="hljs-keyword">import</span> javax.servlet.http.HttpSession;<br><br><span class="hljs-meta">@Log4j2</span><br><span class="hljs-meta">@Controller</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserAction</span> &#123;<br><br>    <span class="hljs-meta">@GetMapping(&quot;/user.html&quot;)</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">toUserCenter</span><span class="hljs-params">()</span>&#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;redirect:/user/info.html&quot;</span>;<br>    &#125;<br><br>    <span class="hljs-meta">@GetMapping(&quot;/user/info.html&quot;)</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">toInfo</span><span class="hljs-params">(HttpSession session, ModelMap modelMap)</span>&#123;<br>        <span class="hljs-comment">// 获取当前用户的地址信息</span><br>        <span class="hljs-type">User</span> <span class="hljs-variable">user</span> <span class="hljs-operator">=</span> (User) session.getAttribute(<span class="hljs-string">&quot;userInfo&quot;</span>);<br>        String[] addr = user.getAddress().split(<span class="hljs-string">&quot;-&quot;</span>);<br>        <span class="hljs-comment">// 依次为 省份-城市-地区-详细地址</span><br>        <span class="hljs-keyword">if</span>(addr!=<span class="hljs-literal">null</span> &amp;&amp; addr.length == <span class="hljs-number">4</span>)&#123;<br>            modelMap.addAttribute(<span class="hljs-string">&quot;userProvince&quot;</span>, addr[<span class="hljs-number">0</span>]);<br>            modelMap.addAttribute(<span class="hljs-string">&quot;userCity&quot;</span>, addr[<span class="hljs-number">1</span>]);<br>            modelMap.addAttribute(<span class="hljs-string">&quot;userArea&quot;</span>, addr[<span class="hljs-number">2</span>]);<br>            modelMap.addAttribute(<span class="hljs-string">&quot;userAddress&quot;</span>, addr[<span class="hljs-number">3</span>]);<br>        &#125;<br>        <span class="hljs-comment">// 标记当前页面的类型</span><br>        modelMap.addAttribute(<span class="hljs-string">&quot;type&quot;</span>, <span class="hljs-string">&quot;info&quot;</span>);<br>        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;user&quot;</span>;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h1 id="五、Bug-amp-DeBug"><a href="#五、Bug-amp-DeBug" class="headerlink" title="五、Bug &amp; DeBug"></a>五、Bug &amp; DeBug</h1><hr>
<p>在使用 Bootstrap4.6版本的下拉菜单时报错</p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs apache"><span class="hljs-attribute">bootstrap</span>.js:<span class="hljs-number">1667</span> Uncaught TypeError: Bootstrap&#x27;s dropdowns require Popper (https://popper.js.org)<br>    <span class="hljs-attribute">at</span> Dropdown.show (bootstrap.js:<span class="hljs-number">1667</span>:<span class="hljs-number">17</span>)<br>    <span class="hljs-attribute">at</span> Dropdown.toggle (bootstrap.js:<span class="hljs-number">1635</span>:<span class="hljs-number">12</span>)<br>    <span class="hljs-attribute">at</span> HTMLButtonElement.&lt;anonymous&gt; (bootstrap.js:<span class="hljs-number">1863</span>:<span class="hljs-number">23</span>)<br>    <span class="hljs-attribute">at</span> Function.each (jquery.js:<span class="hljs-number">354</span>:<span class="hljs-number">19</span>)<br>    <span class="hljs-attribute">at</span> jQuery.fn.init.each (jquery.js:<span class="hljs-number">189</span>:<span class="hljs-number">17</span>)<br>    <span class="hljs-attribute">at</span> jQuery.fn.init._jQueryInterface<span class="hljs-meta"> [as dropdown] (bootstrap.js:1848:19)</span><br><span class="hljs-meta">    at HTMLButtonElement.&lt;anonymous&gt; (bootstrap.js:2030:31)</span><br><span class="hljs-meta">    at HTMLDocument.dispatch (jquery.js:5183:27)</span><br><span class="hljs-meta">    at HTMLDocument.elemData.handle (jquery.js:4991:28)</span><br></code></pre></td></tr></table></figure>

<p>解决方式一：在导入bootstrap.js前导入popper.js 脚本，这是下拉菜单用到的拓展插件，插件官网：<a target="_blank" rel="noopener" href="https://popper.js.org/">点击查看</a></p>
<p><code>pom.xml</code></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-comment">&lt;!-- https://mvnrepository.com/artifact/org.webjars.npm/popper.js --&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.webjars.npm<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>popper.js<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.16.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>
<p>Thymeleaf页面导入脚本：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text/javascript&quot;</span> <span class="hljs-attr">th:src</span>=<span class="hljs-string">&quot;@&#123;/webjars/jquery/3.3.1/jquery.js&#125;&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text/javascript&quot;</span> <span class="hljs-attr">th:src</span>=<span class="hljs-string">&quot;@&#123;/webjars/popper.js/1.16.1/dist/umd/popper.js&#125;&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text/javascript&quot;</span> <span class="hljs-attr">th:src</span>=<span class="hljs-string">&quot;@&#123;/webjars/bootstrap/4.6.0/js/bootstrap.js&#125;&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>解决方式二：使用Bootstrap4框架提供的集成后的JS脚本 <code>bootstrap.bundle.js</code></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text/javascript&quot;</span> <span class="hljs-attr">th:src</span>=<span class="hljs-string">&quot;@&#123;/webjars/bootstrap/4.6.0/js/bootstrap.bundle.js&#125;&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br></code></pre></td></tr></table></figure>



                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98-%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2-0/" class="category-chain-item">项目实战:购物系统v2.0</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/JavaWeb/">#JavaWeb</a>
      
        <a href="/tags/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98-%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2-0/">#项目实战:购物系统v2.0</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Web项目实战 _ 购物系统v2.0 _ 开发记录（四）单个页面单个请求解决根据商品类型进行分页查询 _ 使用省市区三级联动 _ 使用JQuery 插件实现图片上传</div>
      <div>http://example.com/2022/02/05/Web项目实战 _ 购物系统v2.0 _ 开发记录（四）单个页面单个请求解决根据商品类型进行分页查询 _ 使用省市区三级联动 _ 使用JQuery 插件实现图片上传/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年2月5日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/02/06/Web%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20_%20%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2.0%20_%20%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95%EF%BC%88%E5%85%AD%EF%BC%89%E5%95%86%E5%93%81%E8%AF%A6%E6%83%85%E9%A1%B5%E9%9D%A2%20_%20%E6%B8%B8%E5%AE%A2%E8%AE%BF%E9%97%AE%E4%B8%BB%E9%A1%B5%20_%20%E8%BF%90%E7%94%A8Bootstrap4%E8%BD%BB%E9%87%8F%E7%BA%A7%E5%BC%B9%E7%AA%97%E5%AE%9E%E7%8E%B0%E6%8F%90%E7%A4%BA/" title="Web项目实战 _ 购物系统v2.0 _ 开发记录（六）商品详情页面 _ 游客访问主页 _ 运用Bootstrap4轻量级弹窗实现提示">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Web项目实战 _ 购物系统v2.0 _ 开发记录（六）商品详情页面 _ 游客访问主页 _ 运用Bootstrap4轻量级弹窗实现提示</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/02/01/%E6%9C%88%E5%BA%A6%E6%80%BB%E7%BB%93%20_%202022%E5%B9%B401%E6%9C%88%20_%20%E5%A4%A7%E4%B8%89%E6%9C%9F%E6%9C%AB%E8%80%83%E8%AF%95%E6%8F%90%E5%89%8D%20_%20%E5%87%86%E5%A4%87%E6%9C%9F%E6%9C%AB%E8%80%83%E6%80%BB%E7%BB%93%20_%20%E5%81%87%E6%9C%9F%E5%AD%A6%E4%B9%A0%E8%AE%B0%E5%BD%95%E6%80%BB%E7%BB%93%20_%20%E6%9C%88%E5%BA%A6%E6%94%B6%E8%8E%B7%E6%80%BB%E7%BB%93%E3%80%81%E5%BF%83%E5%BE%97%E4%B8%8E%E5%B1%95%E6%9C%9B/" title="月度总结 _ 2022年01月 _ 大三期末考试提前 _ 准备期末考总结 _ 假期学习记录总结 _ 月度收获总结、心得与展望">
                        <span class="hidden-mobile">月度总结 _ 2022年01月 _ 大三期末考试提前 _ 准备期末考总结 _ 假期学习记录总结 _ 月度收获总结、心得与展望</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
